<?php

class Gmapsprofile_Form_Admin_Settings extends Engine_Form
{
  public $_fieldType = 'user';
  protected $_requireProfileType = true;
  
  public function init()
  {

    $this->setMethod('post');
    $this->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array()));

	//Profile Fields
	
    // Set data
    $mapData = Engine_Api::_()->getApi('core', 'fields')->getFieldsMaps($this->_fieldType);
    $metaData = Engine_Api::_()->getApi('core', 'fields')->getFieldsMeta($this->_fieldType);
    $optionsData = Engine_Api::_()->getApi('core', 'fields')->getFieldsOptions($this->_fieldType);
	
	//Get profile_type
	$profile_type = $metaData->getRowMatching('type', 'profile_type');
    $LevelOption = $optionsData->getRowsMatching('field_id', $profile_type->field_id);
    if( !$LevelOption ) {
      throw new Engine_Exception('Missing field');
    }

	foreach( $LevelOption as $option ) {
	  $option_id = $option->option_id;
	  $multiOptions = array();
	  // Get second level fields
      $secondLevelMaps = array();
      if( !empty($option_id) ) {
        $secondLevelMaps = $mapData->getRowsMatching('option_id', $option_id);
        if( !empty($secondLevelMaps) ) {
          foreach( $secondLevelMaps as $map ) {
            $oField = $map->getChild();
 		    if ($oField && $oField->type != 'heading')
	  	      $multiOptions[$oField->field_id] = $oField->label;
	   	  }
        }
      }
    $this->addElement('MultiCheckbox', 'level_' . $option_id, array(
      'label' => $option->label,
      'description' => 'Choose correct address fields',
      'multiOptions' => $multiOptions
    ));
    }
	
    $this->addElement('Select', 'scale_profile', array(
      'label' => 'Zoom for My Location',
      'description' => '',
      'multiOptions' => array(
        19  =>   '10 m',
		18  =>   '20 m',
		17  =>   '50 m',
		16  =>   '100 m',
		15  =>   '200 m',
		14  =>   '500 m',
		13  =>   '1000 m',
		12  =>   '2000 m',
		11  =>   '5000 m',
		10 =>   '10000 m',
		9 =>   '20000 m',
		8 =>   '30000 m',
		7 =>   '50000 m',
		6 =>   '100000 m',
		5 =>   '200000 m',
		4 =>   '500000 m',
		3 =>   '1000000 m',
		2 =>   '2000000 m',
		1 =>   '5000000 m',
		0 =>   '10000000 m',
      )
    ));
	
    $this->addElement('Radio', 'type_map', array(
      'label' => 'Map Type for My Location',
      'description' => '',
      'required' => true,
      'multiOptions' => array(
        'ROADMAP' => 'Roadmap',
        'SATELLITE' => 'Satellite',
        'HYBRID' => 'Hybrid',
		'TERRAIN' => 'Terrain'		
      ),
    ));
	
    $this->addElement('Select', 'scale_friends', array(
      'label' => 'Zoom for Friends Location',
      'description' => '',
      'multiOptions' => array(
        19  =>   '10 m',
		18  =>   '20 m',
		17  =>   '50 m',
		16  =>   '100 m',
		15  =>   '200 m',
		14  =>   '500 m',
		13  =>   '1000 m',
		12  =>   '2000 m',
		11  =>   '5000 m',
		10 =>   '10000 m',
		9 =>   '20000 m',
		8 =>   '30000 m',
		7 =>   '50000 m',
		6 =>   '100000 m',
		5 =>   '200000 m',
		4 =>   '500000 m',
		3 =>   '1000000 m',
		2 =>   '2000000 m',
		1 =>   '5000000 m',
		0 =>   '10000000 m',
      )
    ));
	
    $this->addElement('Radio', 'type_map_friends', array(
      'label' => 'Map Type for Friends Location',
      'description' => '',
      'required' => true,
      'multiOptions' => array(
        'ROADMAP' => 'Roadmap',
        'SATELLITE' => 'Satellite',
        'HYBRID' => 'Hybrid',
		'TERRAIN' => 'Terrain'		
      ),
    ));	

    $this->addElement('Button', 'submit', array(
      'label' => 'Save Settings',
      'type' => 'submit',
    ));
  }  
}